/**
 * Copyright © 2022 易久批信息技术有限公司. All rights reserved.
 */
package com.dysm.multithread;


import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.util.function.Function;

/**
 *
 * @author xiay
 * @since 2022/3/26 8:47 下午
 */
public class CallableTest {

    public static void main(String[] args) throws Exception {
        MyCallable myCallable = new MyCallable((a) -> a * a, 12);
        FutureTask<Integer> futureTask = new FutureTask<>(myCallable);
        new Thread(futureTask);
        Integer integer = futureTask.get();
        System.out.println(integer);
    }

    static class MyCallable implements Callable<Integer> {

        private Function<Integer, Integer> function;

        private int param;

        public MyCallable(Function<Integer, Integer> function, int param) {
            this.function = function;
            this.param = param;
        }

        public Integer call() throws Exception {
            return function.apply(param);
        }
    }
}
